home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 March / macformat-035.iso / Shareware City / Developers / ICAppSourceKit1.2 / ICGlobals.p < prev    next >
Encoding:
Text File  |  1995-11-07  |  3.8 KB  |  140 lines  |  [TEXT/CWIE]

  1. unit ICGlobals;
  2.  
  3. interface
  4.  
  5.     uses
  6.         ICTypes, Files, Events;
  7.  
  8.     const
  9.         M_File = 129;
  10.         M_Edit = 130;
  11.         M_Install = 131;
  12.         M_Windows = 132;
  13.  
  14.     const
  15.         EM_Undo = 1;
  16.         (* *)
  17.         EM_Cut = 3;
  18.         EM_Copy = 4;
  19.         EM_Paste = 5;
  20.         EM_Clear = 6;
  21.         EM_SelectAll = 7;
  22.  
  23.     const
  24.         FM_New = 1;
  25.         FM_Open = 2;
  26.         FM_OpenInternetPreferences = 3;
  27.         (* *)
  28.         FM_Close = 5;
  29.         FM_Save = 6;
  30.         FM_SaveAs = 7;
  31.         (* *)
  32.         FM_Quit = 9;
  33.  
  34.     const
  35.         IM_Install = 1;
  36.         IM_Save = 2;
  37.         IM_Remove = 3;
  38.  
  39.     const                                    { Other OS constants, probably declared somewhere now }
  40.         kSysEnvironsVersion = 1;
  41.         kOSEvent = osEvt;                {event used by MultiFinder}
  42.         kSuspendResumeMessage = 1;    {high byte of suspend/resume event message}
  43.         kResumeMask = 1;                    {bit of message field for resume vs. suspend}
  44.         kMouseMovedMessage = $FA;    {high byte of mouse-moved event message}
  45.         kNoEvents = 0;                        {no events mask}
  46.  
  47.     var  { set up by InitSystemGlobals }
  48.         system7: boolean;
  49.         has_appleEvents: boolean;
  50.         has_findfolder: boolean;
  51.         has_aliasMgr: boolean;
  52.         has_newStdFile: boolean;
  53.         has_HelpMgr: boolean;
  54.         has_colorQD: boolean;
  55.         has_components: boolean;
  56.         app_resfile: integer;
  57.         app_fs: FSSpec;
  58.         in_foreground: boolean;
  59.         quitNow: boolean;
  60.         app_version: VersRec;
  61.  
  62.     procedure InitGlobals;
  63.  
  64.     function InForeground: boolean;
  65.  
  66.     type
  67.         icAction = (acDoThis, acInstallComponent, acOpenWindow, acNewDocument, acOpenDocument, acCloseWindow, acSave, {}
  68.             acQuit, acStartApplication, acGetExample, acChooseApplication, acRemoveComponent, acSetDefaults, acSort);
  69.  
  70.     procedure DisplayError (action: icAction; err: OSErr);
  71.  
  72. implementation
  73.  
  74.     uses
  75.         Errors, Processes, Components, GestaltEqu, Resources, ToolUtils, Dialogs, ICMiscSubs;
  76.  
  77.     procedure InitGlobals;
  78.         var
  79.             oe: OSErr;
  80.             gv: longInt;
  81.             pb: FCBPBRec;
  82.             sysenv: sysEnvRec;
  83.             versh: VersRecHndl;
  84.     begin
  85.         app_resfile := CurResFile;
  86.         pb.ioNamePtr := @app_fs.name;
  87.         pb.ioVRefNum := 0;
  88.         pb.ioRefNum := app_resfile;
  89.         pb.ioFCBIndx := 0;
  90.         oe := PBGetFCBInfoSync(@pb);
  91.         app_fs.vRefNum := pb.ioFCBVRefNum;
  92.         app_fs.parID := pb.ioFCBParID;
  93.         has_colorqd := (SysEnvirons(1, sysEnv) = noErr) & sysenv.hasColorQD; { Gestalt has a bug that causes hasColourQD to always be set }
  94.         system7 := (Gestalt(gestaltSystemVersion, gv) = noErr) & (gv >= $0700);
  95.         has_AppleEvents := (Gestalt(gestaltAppleEventsAttr, gv) = noErr) & (TPbtst(gv, gestaltAppleEventsPresent));
  96.         has_findfolder := (Gestalt(gestaltFindFolderAttr, gv) = noErr) & (TPbtst(gv, gestaltFindFolderPresent));
  97.         has_newStdFile := (Gestalt(gestaltStandardFileAttr, gv) = noErr) & (TPbtst(gv, gestaltStandardFile58));
  98.         has_HelpMgr := (Gestalt(gestaltHelpMgrAttr, gv) = noErr) & (TPbtst(gv, gestaltHelpMgrPresent));
  99.         has_aliasMgr := (Gestalt(gestaltAliasMgrAttr, gv) = noErr) & (TPbtst(gv, gestaltAliasMgrPresent));
  100.         has_components := (Gestalt(gestaltComponentMgr, gv) = noErr) & (gv > 0);
  101.         versh := VersRecHndl(Get1Resource('vers', 1));
  102.         if versh <> nil then begin
  103.             app_version := versh^^;
  104.         end else begin
  105.             longInt(app_version.numericVersion) := 0;
  106.             app_version.countryCode := 0;
  107.             app_version.shortVersion := '';
  108.         end; (* if *)
  109.     end;
  110.  
  111.     function InForeground: boolean;
  112.         var
  113.             gv: longInt;
  114.             ourpsn, frontpsn: ProcessSerialNumber;
  115.             front: boolean;
  116.     begin
  117.         if (Gestalt(gestaltOSAttr, gv) = noErr) & (TPbtst(gv, gestaltLaunchControl)) then begin
  118.             if (GetCurrentProcess(ourpsn) = noErr) & (GetFrontProcess(frontpsn) = noErr) then begin
  119.                 if SameProcess(ourpsn, frontpsn, front) = noErr then
  120.                     in_foreground := front;
  121.             end;
  122.         end;
  123.         InForeground := in_foreground;
  124.     end;
  125.  
  126.     procedure DisplayError (action: icAction; err: OSErr);
  127.         var
  128.             junk: integer;
  129.             tmp, tmp2: Str255;
  130.     begin
  131.         if (err <> noErr) and (err <> userCanceledErr) then begin
  132.             InitCursor;
  133.             GetIndString(tmp, 131, ord(action) + 1);
  134.             NumToString(err,tmp2);
  135.             ParamText(tmp, tmp2, '', '');
  136.             junk := StopAlert(140, nil);
  137.         end; (* if *)
  138.     end; (* DisplayError *)
  139.  
  140. end. (* ICGlobals *)